package com.ganlebao.study.springcloudzuulbackserver;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("zuul/header/")
public class HeaderController {
    /**
     * 测试 set-cookies是否被gateway返回
     *
     * @param response
     * @return
     */
    @GetMapping("no-cookie")
    public String addCookie(HttpServletResponse response) {
        Cookie cookie = new Cookie("user-name", "glb");
        response.addCookie(cookie);
        return "add-cookies";
    }

    @GetMapping("ignore-header")
    public Map<String, String> ignoreHeader(@RequestHeader(value = "custom", required = false) String headerValue, @RequestHeader(value = "Accept", required = false) String accept) {
        Map<String, String> result = new HashMap<>();
        result.put("custom", headerValue);
        result.put("accept", accept);
        return result;
    }
}
